"""
二值化与反二值化
"""
import cv2

img = cv2.imread('../data/lena.jpg',0)
# cv2.imshow('img',img)

# 二值化
t,binary = cv2.threshold(img,
                         100, # 阈值
                         255, # 大于阈值转化为255
                         cv2.THRESH_BINARY #二值化
                         )

cv2.imshow('binary',binary)

# 反二值化
t1,binary_inv = cv2.threshold(img,
                         100, # 阈值
                         255, # 大于阈值转化为255
                         cv2.THRESH_BINARY_INV #二值化
                         )

cv2.imshow('binary_inv',binary_inv)


cv2.waitKey()
cv2.destroyAllWindows()